﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace omaura_oled
{
    /// <summary>
    /// Log Class writing the log (error/debug) in .\Log.txt
    /// - debug / error tracking
    /// </summary>
    public class Log
    {
        #region "Methods"
        //- Method Write: Write in .\Log.txt
        public static void Write(object obj)
        {
            string text = DateTime.Now.ToString() + " - " + obj.ToString();
            string line;

            using (StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\omaura\\omaura oled\\Log-oled.txt"))
            {
                line = sr.ReadToEnd();
            }

            string linetmp = line + text;
            using (StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\omaura\\omaura oled\\Log-oled.txt"))
            {
                sw.WriteLine(linetmp);
            }
        }
        //- Method Erase: empty the file
        public static void Erase()
        {
            string EmptyLine = "";

            using (StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\omaura\\omaura oled\\Log-oled.txt"))
            {
                sw.Write(EmptyLine);
            }
        }
        //--
        #endregion "Methods"
    }
}

